package com.online.teaching.dao;
import com.online.teaching.pojo.Comment;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:admin
 * @Description:Comment的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface CommentMapper extends Mapper<Comment> {
    /**
     * 管理员获取博客列表
     * @param blogId
     * @return
     */
    @Select("SELECT * from `comment` WHERE is_value=1 AND blog_id = #{blog_id}")
    public List<Comment> adminGetCommentList(@Param("blog_id") Integer blogId);

    /**
     * 管理员删除评论时将所对应的回复id变成0
     * @param replyId
     */
    @Update("UPDATE `comment` SET reply_id=0 WHERE reply_id=#{reply_id}")
    public void updateReplyId(@ApiParam("reply_id") Integer replyId);

    /**
     * 删除博客时将其全部评论状态设置为0
     * @param blogId
     */
    @Update("UPDATE `comment` SET is_value=0 WHERE blog_id=#{blog_id}")
    public void deleteBlog(@ApiParam("blog_id") Integer blogId);

    /**
     * 删除一条评论
     * @param commentId
     */
    @Update("UPDATE `comment` SET is_value=0 WHERE comment_id=#{comment_id}")
    public Integer deleteComment(@ApiParam("comment_id")Integer commentId);

}
